<?php
	use\ampleharvest\cConfig;
	header("Content-type: application/x-javascript");

	require_once dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/config/cConfig.php';
	
	$webConfig = new \ampleharvest\cConfig();
	require_once $webConfig->C_STR_AMPLEHARVEST_CODE . '/classes/Tables/cTABLE_Metric.php';
?>

Ext.define("AmpleHarvestPHP.DATA.Store.statistics.cMetrics",
{
	extend			: 'Ext.data.Store',
	requires		:
	[
		"AmpleHarvest.DATA.Model.cKeyValue"
	],
	statics			:
	{
		C_STR_TYPE_TOTAL_PAGES	: "<?php print(cTABLE_Metric::C_STR_CATEGORY_TOTAL_PAGES); ?>",
		C_STR_TYPE_TOTAL_USERS	: "<?php print(cTABLE_Metric::C_STR_CATEGORY_TOTAL_USERS); ?>",

		C_STR_SUBTYPE_HOURLY	: "<?php print(cTABLE_Metric::C_STR_SUBCATEGORY_HOURLY); ?>",
		C_STR_SUBTYPE_DAILY		: "<?php print(cTABLE_Metric::C_STR_SUBCATEGORY_DAILY); ?>",
		C_STR_SUBTYPE_MONTHLY	: "<?php print(cTABLE_Metric::C_STR_SUBCATEGORY_MONTHLY); ?>",
		C_STR_SUBTYPE_YEARLY	: "<?php print(cTABLE_Metric::C_STR_SUBCATEGORY_YEARLY); ?>",

		C_STR_GROUP_SOLR		: "<?php print(cTABLE_Metric::C_STR_GROUP_SOLR); ?>",
		C_STR_GROUP_ACTIVE		: "<?php print(cTABLE_Metric::C_STR_GROUP_ACTIVE); ?>",
		C_STR_GROUP_TOTAL		: "<?php print(cTABLE_Metric::C_STR_GROUP_TOTAL); ?>"
	},
	m_obj_Params	: null,
	// model : 'AmpleHarvest.DATA.Model.cKeyValue',
	fields			:
	[
			{
				name		: 'label',
				// type : 'string',
				type		: 'date',
				dateFormat	: 'Y-m-d H:i:s'
			},
			{
				name	: 'data',
				type	: 'NUMBER'
			}
	],
	proxy			:
	{
		type	: 'ajax',
		url		: obj_config.C_STR_EXTERNAL_PATH+'/rest/statistics/metrics.php',
		reader	:
		{
			type			: 'json',
			totalProperty	: "total",
			root			: 'data'
		},
		timeout	: 100000
	},
	initComponent	: function()
	{
		this.m_obj_Params = new Object();
		this.callParent();
	},
	setSubType		: function(str_Type)
	{
		if (!this.m_obj_Params)
		{
			this.m_obj_Params = new Object;
		}
		this.m_obj_Params.subcategory = str_Type;

		this.set_Params();
	},
	setGroup		: function(str_Group)
	{
		if (!this.m_obj_Params)
		{
			this.m_obj_Params = new Object;
		}
		this.m_obj_Params.group = str_Group;

		this.set_Params();
	},
	setType			: function(str_Type)
	{
		if (!this.m_obj_Params)
		{
			this.m_obj_Params = new Object;
		}
		this.m_obj_Params.category = str_Type;

		this.set_Params();
	},
	setStartDate	: function(obj_StartDate)
	{
		if (!this.m_obj_Params)
		{
			this.m_obj_Params = new Object;
		}
		this.m_obj_Params.startDate = Ext.Date.format(obj_StartDate,
				"d-m-Y 0:0:0"
		);

		this.set_Params();
	},
	setEndDate		: function(obj_Date)
	{
		if (!this.m_obj_Params)
		{
			this.m_obj_Params = new Object;
		}
		this.m_obj_Params.endDate = Ext.Date.format(obj_Date, "d-m-Y 23:59:59");

		this.set_Params();
	},
	set_Params		: function()
	{
		if (!this.m_obj_Params)
		{
			this.m_obj_Params = new Object;
		}
		this.proxy.extraParams = this.m_obj_Params;
	}
}
);
